#include<bits/stdc++.h>
using namespace std;
int t,n,a[100005],vis[100005],ans;
int check(int x)
{
    for(int i=x-1;i>=1;i--)
    {
        if(vis[i]==vis[x])
        {
            if(a[i]==a[x])
                return a[x];
            else
                return 0;
        }
    }
    return 0;
}
void dfs(int deep,int cnt)
{
    if(deep>n)
    {
        ans=max(ans,cnt);
        return;
    }
    vis[deep]=1;
    dfs(deep+1,cnt+check(deep));
    vis[deep]=2;
    dfs(deep+1,cnt+check(deep));
    vis[deep]=0;
}
int main()//pts20
{
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
    scanf("%d",&t);
    while(t--)
    {
        ans=-1;
        memset(vis,0,sizeof(vis));
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",a+i);
        dfs(1,0);
        printf("%d\n",ans);
    }

	return 0;
}
